<?php
/**
 * User: tridungpham
 * Date: 7/6/11
 * Time: 12:25 AM
 */
 
class TemplateController extends ExtendedController
{
    function __construct()
    {
        parent::__construct();
        $this->loadModel('template');
    }
    
    function index()
    {
        $data =& $this->models['template']->getTemplateList();

        $view = $this->loadView('index');
        $view->setBlockData($data);
        $view->render();
    }

    function detail($id)
    {
        $data =& $this->models['template']->getTemplateDetail($id);
        $array['id'] =& $id;
        $array['data'] =& $data;
        $view = $this->loadView('detail');
        $view->setBlockData($array);
        $view->render();
    }

    function add($type,$id = NULL)
    {
        if(isset($_POST['submit']))
        {
            $this->models['template']->handleAction($type);
        }

        switch($type)
        {
            case 'template':
                break;

            case 'block':
                {
                    $array['action'] = 'add';
                    $array['template_id'] = $id;

                    $view = $this->loadView('block_form');
                    $view->setBlockData($array);
                    $view->render();
                }
        }
    }
}